﻿using System.ComponentModel;
using VisualWip.Core;
using VisualWip.Core.Columns;
using VisualWip.Core.Utils;
using VisualWip.PresentationModel.WorkItem;

namespace VisualWip.PresentationModel.Slots
{
    public class SlotViewModel : INotifyPropertyChanged
    {
        private readonly WorkColumnBase _column;
        private readonly Slot _slot;
        private readonly WorkItemViewModel _workItemViewModel;

        public SlotViewModel(Slot slot, WorkColumnBase column)
        {
            _slot = slot;
            _column = column;
            _column.PropertyChanged += ColumnPropertyChanged;
            _workItemViewModel = WorkItemViewModelFactory.Create(_slot, column);
        }

        public WorkItemViewModel WorkItem
        {
            get { return _workItemViewModel; }
        }

        public bool IsAvailableSlot
        {
            get { return _slot.IsAvailableSlot; }
        }

        public bool HasWorkInProgressLimit
        {
            get { return _column.HasWorkInProgressLimit; }
        }

        public bool IsInWorkInProgressLimit
        {
            get { return _slot.IsInWorkInProgressLimit; }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        private void ColumnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == PropertyHelper.Name(() => HasWorkInProgressLimit))
                PropertyHelper.OnPropertyChanged(this, PropertyChanged,
                                                 () => HasWorkInProgressLimit);
        }
    }
}